package com.zhuojy.equity.mall.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.AddressBook;
import com.zhuojy.equity.mall.admin.common.entity.Document;
import com.zhuojy.equity.mall.admin.dal.mapper.AddressBookMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@RequiredArgsConstructor
@Service
@Slf4j
public class AddressBookService extends ServiceImpl<AddressBookMapper, AddressBook> {


    public IPage queryAddress(AddressBook addressBook) {
        IPage page = new Page<>(addressBook.getCurrentPage(),addressBook.getPageSize());
        LambdaQueryWrapper<AddressBook> lambdaQueryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.hasText(addressBook.getName())){
            lambdaQueryWrapper.like(AddressBook::getName,addressBook.getName());
        }
        if (addressBook.getFromColumn()!=null){
            lambdaQueryWrapper.like(AddressBook::getFromColumn,addressBook.getFromColumn());
        }
        page =page(page,lambdaQueryWrapper);
        return page;
    }

    /**
     * s删除
     * @param id
     */
    public void deleteAddress(Integer id) {
    this.baseMapper.deleteById(id);
    }

    /**
     * 新增修改
     * @param addressBook
     */
    public void addAddress(AddressBook addressBook) {
        if(addressBook.getId()!=null){
            this.baseMapper.updateById(addressBook);
        }else{
            this.baseMapper.insert(addressBook);
        }
    }
}
